import React from 'react';
import ReactDOM from 'react-dom';
import { defineMicroApp } from '@deepfos/micro-app';
import type { AppProps } from './App';
import App from './App';

// 1. 普通方式渲染
// eslint-disable-next-line no-underscore-dangle
if (!window.__microAppEnv__) {
  // 运行时全局样式
  if (import.meta.env.DEV) {
    await Promise.all([
      import('antd/dist/antd.less'),
      import('@deepfos/theme/es/global.less'),
      import('./global.less'),
    ]);
  }
  // eslint-disable-next-line react/no-deprecated
  ReactDOM.render(<App />, document.getElementById('root'));
}

// 2. 通过微应用加载渲染
export default defineMicroApp<AppProps>(() => {
  return {
    render(props) {
      return <App {...props} />;
    },
  };
});
